package com.gong.bank.controller;

import com.gong.bank.model.UserBean;
import com.gong.bank.service.BankService;
import com.gong.bank.service.BankServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:
 * @author:gong
 * @create: 4/8/2022 上午8:47
 */
public class UserController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BankService service = new BankServiceImpl();
        UserBean userInfo = (UserBean) req.getSession().getAttribute("userInfo");
        String changename = req.getParameter("changename");
        String role = req.getParameter("role");
        service.updateAdmin(service.findUserByName(changename), Integer.parseInt(role));
        req.setAttribute("user",userInfo);
        req.getRequestDispatcher("main.jsp").forward(req,resp);
    }
}
